const daoMethod = require('../utils/daoCommon');

const dao = {
    /**
     * 添加Token值
     * @param data
     * @returns {*}
     */
    addToken: (data) => {
        let sql = `insert into Token value($Token, $UserId)`;
        return daoMethod.oneMethod(sql, data);
    },
    /**
     * 修改Token值没有就插入数据有就修改
     * @param data
     * @returns {*}
     */
    updateToken: (data) => {
        let sql = `insert into token(Token,UserId) values($Token,$UserId) on DUPLICATE KEY UPDATE Token=$Token`;
        return daoMethod.oneMethod(sql, data);
    },
    /**
     * 查询指定用户Token值
     * @param data
     * @returns {*}
     */
    queryTokenByUser: (data) => {
        let sql = `select token from Token where UserId = $UserId`;
        return daoMethod.oneMethod(sql, data);
    },
    /**
     * 查询用户的用户id值
     * @param data
     * @returns {*}
     */
    queryUserIdByToken: (data) => {
        let sql = `select UserId from token where Token = $Token`;
        return daoMethod.oneMethod(sql, data);
    }
};

module.exports = dao;